from constant import *


class PlantMessage:
    def __init__(self, name: str, plant_property: str, other_property: str, price: int, hp: int,card, card_path: list[str],
                 plant, plant_path: str):
        self.name = name
        self.card = card
        self.card_path = card_path
        self.price = price
        self.hp = hp
        self.plant = plant
        self.plant_path = plant_path
        self.property = plant_property
        self.other_property = other_property


class PlantObject(GifObject):
    def __init__(self, screen: pg.Surface, plant: PlantMessage, row, column):
        super().__init__(screen, plant.plant_path, coordinate=(LAWN_START_X + column * LAWN_WIDTH, LAWN_START_Y + row * LAWN_HEIGHT))
        self.property = plant.property
        self.other_property = plant.other_property
        self.row = 0
        self.column = 0
        self.price = plant.price
        self.total_hp = plant.hp
        self.now_hp = plant.hp
        self.over = False
        self.hp = HP(screen, self.now_hp, self.total_hp, self.coordinate)

    def update(self):
        if self.now_hp == 0:
            self.over = True
        self.hp.now_hp = self.now_hp
        self.screen.blit(self.state[self.frame_number], self.coordinate)
        self.hp.update()
        self.frame_number = self.frame_number + 1 if self.frame_number < self.state_cycle - 1 else 0

    def hurt(self, *args):
        pass


class Pea(GifObject):
    def __init__(self, screen: pg.Surface, coordinate):
        super().__init__(screen, 'images\\Plants\\PB00.gif')
        self.trajectory = points_trajectory(coordinate, (SCREEN_WIDTH, coordinate[1]))


class Peashooter(PlantObject):
    def __init__(self, screen: pg.Surface, row, column):
        self.plant = PlantMessage('Peashooter', 'grassland', 'alone', 100, 100, None,
                                  ['images\\Card\\Plants\\Peashooter1.png', 'images\\Card\\Plants\\Peashooter2.png'],
                                  Peashooter, 'images\\Plants\\Peashooter\\Peashooter.gif')
        super().__init__(screen, self.plant, row, column)
        self.peas = []

    def hurt(self, zombies):
        zombies = zombies[self.row].zombies
        for zombie in zombies:
            if zombie.coordinate[1] > self.coordinate[1]:
                self.peas.append(Pea(self.screen, self.coordinate))

    def update(self):
        print(self.peas)
        if self.now_hp == 0:
            self.over = True
        self.hp.now_hp = self.now_hp
        self.screen.blit(self.state[self.frame_number], self.coordinate)
        for pea in self.peas:
            pea.update()
        self.hp.update()
        self.frame_number = self.frame_number + 1 if self.frame_number < self.state_cycle - 1 else 0



